import BaseView from "../baseView.js";

export default class addadmins extends BaseView {
  render() {
    $("#Content").html(`
         <div>
         <div style="margin: 30px 10px 0 20px ">
         <span class="layui-breadcrumb" style="visibility: visible;">
             <a>学生管理系统/</a>/
             <a>学生资料管理/</a>/
             <a>添加管理员</a>
          </span>
          <hr/>
         </div>
         <div>
         <form class="layui-form" id = "addGoodsForm">
         <div class="layui-form-item">
         <label class="layui-form-label">管理员账号:</label>
           <div class="layui-input-block">
             <input type="text" id="movieId" required   placeholder="请输入注册账号"  class="layui-input">
           </div>
         </div>
         <div class="layui-form-item">
         <label class="layui-form-label">管理员密码:</label>
           <div class="layui-input-block">
             <input type="text" id="cinemasId" required   placeholder="请输入管理员"  class="layui-input">
           </div>
         </div>
         

         </div>
         </div>
         <div class="layui-form-item">
           <div class="layui-input-block">
             <button type='button' id='addstudentBtn' class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
             <button type="reset" class="layui-btn layui-btn-primary" id="chongzhi">重置</button>
             <button type="reset" class="layui-btn layui-btn-primary" id="back">返回</button>
           </div>
         </div>
       </form>
         </div>
         
         </div>
        `)
  }
  handle() {
    $("#addLayuijs").html(`
       <script>
        layui.use('form', function(){
        var form = layui.form;
         //重新渲染表单
         form.render();
        });
        </script>
         `)

    //绑定添加事件
    $("#addstudentBtn").click(() => {
      $.ajax({
        type: "post",
        url: "/admins/reg",
        data: {
          "username": $("#movieId").val(),
          "password": $("#cinemasId").val(),
        },
        dataType: "json",
        success: (data) => {
          console.log(data)
          if (data.code == 1) {
            alert(data.msg);
            window.location.hash = "#/main/adminsList";
          } else {
            alert(data.msg);
          }
        }
      })
    })

    $("#back").click(() => {
      window.location.hash = "#/main/adminsList";
    })

    $("#chongzhi").click(() => {
        // 清空表单数据
        $("#addGoodsForm")[0].reset();
        layui.form.render();
    })

  }
}